<template>
  <div class="myProject-warp">
    <ul class="myProject">
      <li v-for="(item,index) in list" :key="index" @click="pageSkip(item.ID)">
        <div class="project">
          <span class="project-status"
            :style="item.TrainingLevel=='不合格'?'background:#ff6600':item.TrainingLevel=='优秀'?'background:#cc0001':'background:#1da081'"></span>
          <div class="project-info">
            <div class="project-name">
              {{item.Name}}</div>
            <div class="project-time">{{item.BTime}} 至 {{item.ETime}}</div>
          </div>
          <div class="project-if-qualified" v-if="item.TrainingLevel!=null"
            :style="item.TrainingLevel=='不合格'?'background:#ff6600':item.TrainingLevel=='优秀'?'background:#cc0001':'background:#1da081'">
            {{item.TrainingLevel}}</div>
        </div>
      </li>
        <p style="text-align: center" v-if="moreText">下拉加载更多</p>
        <p style="text-align: center" v-if="noMoreText">没有更多数据了</p>
    </ul>
      <div class="no-data-wrap" v-if="showNoData">
          <img src="../../../static/tabs/noData.png" alt="">
      </div>
      <van-toast id="van-toast" />
  </div>
</template>
<script>
  import { MyTrainingList } from '@/providers/service'
  export default {

    data() {
      return {
        list: [],
        PageIndex: 0,
        showNoData:false,
        moreText:false,
        noMoreText:false
      };
    },
    onReachBottom() {
      if(!this.moreText){ return false}
      this.initialize();
  },
    onPullDownRefresh() {
      this.PageIndex = 0;
      this.dataList = []
        this.moreText = false
        this.noMoreText = false
      this.initialize();
      wx.stopPullDownRefresh()
        this.$toast('刷新成功')
    },
    onShow() {
      this.list = []
      this.PageIndex = 0;
      this.moreText = false
      this.noMoreText = false
      this.initialize();
    },
      onUnload(){
        this.showNoData = false
      },

    methods: {
      initialize() {
        this.userInfo = wx.getStorageSync('userInfo')
        let { RoleCode, UserID } = this.userInfo
        MyTrainingList({ UserID: UserID, PageSize: 10, PageIndex: this.PageIndex, RoleCode }).then((res) => {
        this.dataFilter(res)
        })
      },
      // 上下拉数据处理
      dataFilter(origdata) {
          let headhuntListDateOne = origdata.QXTrainingList
          let _list = headhuntListDateOne && headhuntListDateOne.length ? headhuntListDateOne : []
          //noData
          if (!_list.length) {
                if(this.PageIndex===0){
                    this.showNoData = true
                }else{
                    this.noMoreText = true
                    this.moreText = false
                }
          }else{
              this.noMoreText = _list.length < 10 ?true:false
              this.moreText = !this.noMoreText
              this.PageIndex = this.PageIndex + 1;
              for (let originitem of headhuntListDateOne) {
                  let ifOriginDate = this.list.filter(item => {
                      return originitem.ID === item.ID
                  })
                  if (ifOriginDate.length < 1) {
                      this.list.push(originitem)
                  }
              }
            }
          },
      pageSkip(data) {
        this.$router.push({ path: '/pages/projecReport/projecReport', query: { TID: data } })
      }
    }
  };
</script>
<style lang="less" scoped>
  .no-data-wrap{
      text-align: center;
      transform: translateY(30%);
  }
  .myProject-warp {
    width: 100%;

    .myProject {
      li {
        width: 100%;
        height: 205rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        border-bottom: 1px solid #9e9e9e;

        .project {
          height: 100rpx;
          width: 688rpx;

          .project-status {
            display: inline-block;
            height: 100rpx;
            width: 12rpx;
          }

          .project-info {
            margin-left: 12rpx;
            height: 100rpx;
            display: inline-block;
            width: 524rpx;
            overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
            .project-name {
              font-size: 26rpx;
              overflow: hidden;
             text-overflow:ellipsis;
             max-width: 480rpx;;
             white-space: nowrap;
            }

            .project-time {
              font-size: 20rpx;
              margin-top: 16rpx;
            }
          }

          .project-if-qualified {
            float: right;
            width: 104rpx;
            height: 104rpx;
            border-radius: 50%;
            font-size: 30rpx;
            line-height: 104rpx;
            color: #ffffff;
            text-align: center;
          }
        }
      }
    }
  }
</style>
